package zjh.msg.dao;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import zjh.msg.entity.User;
import zjh.msg.utils.JdbcUtilsV1;

import java.sql.Connection;
import java.sql.SQLException;

public class UserDao {
    public User login(String username, String password) {
        try {
            Connection connection = JdbcUtilsV1.getConnection();
            QueryRunner queryRunner = new QueryRunner();
            String sql = "select id, username from user where username = ? and password = ?";
            User user = queryRunner.query(connection, sql, new BeanHandler<User>(User.class), username, password);
            return user;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }
}
